﻿using System;
using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;


namespace AccessControl.Utility.Report
{
	public partial class TextReportBuilder : XtraUserControl
	{
		#region  Fields

		private XtraReport _report;
		private readonly Boolean _showReportBuilder;

		public delegate void TextReportCreatedEventHandler();
		public event TextReportCreatedEventHandler TextReportCreated;

		#endregion

		#region Constructors

		public TextReportBuilder(Boolean showReportBuilder)
		{
			InitializeComponent();
			_showReportBuilder = showReportBuilder;
		
		}

		#endregion

		#region Public Methods

		public XtraReport Report
		{
			set { _report = value; }
			get { return _report; }
		}

		#endregion

		#region Event Handlers

		private void simpleButtonCreateReprot_Click(object sender, EventArgs e)
		{
			if (ValidateData())
				CreateTextReport();
		}

		#endregion

		#region Private Methods

		protected virtual void CreateTextReport()
		{
			if (TextReportCreated != null)
			{
				TextReportCreated();
			}
		}

		protected virtual bool ValidateData()
		{
			return true;
		}

		#endregion

		private void TextReportBuilder_Load(object sender, EventArgs e)
		{
			if (!_showReportBuilder)
				CreateTextReport();
		}
	}
}
